package com.zfl;

import java.util.ArrayList;
import java.util.List;

public class Subsets {

    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> lists = new ArrayList<>();
        ArrayList<Integer> current = new ArrayList<>();
        int index = 0;
        backtrace(nums,lists,current,index);

        return lists;
    }

    private void backtrace(int[] nums, List<List<Integer>> lists, ArrayList<Integer> current, int index) {
        lists.add(new ArrayList<>(current));
        for (int i = index; i < nums.length; i++) {
            current.add(nums[i]);
            this.backtrace(nums,lists,current,i+1);
            current.remove(current.size()-1);
        }
    }
}
